package com.ruoyi.web.controller.system;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.vo.ZsyyCommunityVo;
import com.ruoyi.system.bo.ZsyyCommunityQueryBo;
import com.ruoyi.system.bo.ZsyyCommunityAddBo;
import com.ruoyi.system.bo.ZsyyCommunityEditBo;
import com.ruoyi.system.service.IZsyyCommunityService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import springfox.documentation.annotations.ApiIgnore;

/**
 * 小区管理Controller
 *
 * @author wangghua
 * @date 2021-07-14
 */
@ApiIgnore
@Api(value = "小区管理控制器", tags = {"小区管理管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/system/community")
public class ZsyyCommunityController extends BaseController {

    private final IZsyyCommunityService iZsyyCommunityService;

    /**
     * 查询小区管理列表
     */
    @ApiOperation("查询小区管理列表")
    @PreAuthorize("@ss.hasPermi('system:community:list')")
    @GetMapping("/list")
    public TableDataInfo<ZsyyCommunityVo> list(@Validated ZsyyCommunityQueryBo bo) {
        return iZsyyCommunityService.queryPageList(bo);
    }
    /**
     * 查询小区管理列表
     */
    @ApiOperation("获取小区下拉列表")
    @GetMapping("/getAllList")
    public AjaxResult getAllList(@Validated ZsyyCommunityQueryBo bo) {
		List<ZsyyCommunityVo> list = iZsyyCommunityService.queryList(bo);
        return AjaxResult.success(list);
    }

    /**
     * 导出小区管理列表
     */
    @ApiOperation("导出小区管理列表")
    @PreAuthorize("@ss.hasPermi('system:community:export')")
    @Log(title = "小区管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<ZsyyCommunityVo> export(@Validated ZsyyCommunityQueryBo bo) {
        List<ZsyyCommunityVo> list = iZsyyCommunityService.queryList(bo);
        ExcelUtil<ZsyyCommunityVo> util = new ExcelUtil<ZsyyCommunityVo>(ZsyyCommunityVo.class);
        return util.exportExcel(list, "小区管理");
    }

    /**
     * 获取小区管理详细信息
     */
    @ApiOperation("获取小区管理详细信息")
    @PreAuthorize("@ss.hasPermi('system:community:query')")
    @GetMapping("/{id}")
    public AjaxResult<ZsyyCommunityVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Long id) {
        return AjaxResult.success(iZsyyCommunityService.queryById(id));
    }

    /**
     * 新增小区管理
     */
    @ApiOperation("新增小区管理")
    @PreAuthorize("@ss.hasPermi('system:community:add')")
    @Log(title = "小区管理", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping()
    public AjaxResult<Void> add(@Validated @RequestBody ZsyyCommunityAddBo bo) {
        return toAjax(iZsyyCommunityService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改小区管理
     */
    @ApiOperation("修改小区管理")
    @PreAuthorize("@ss.hasPermi('system:community:edit')")
    @Log(title = "小区管理", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping()
    public AjaxResult<Void> edit(@Validated @RequestBody ZsyyCommunityEditBo bo) {
        return toAjax(iZsyyCommunityService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除小区管理
     */
    @ApiOperation("删除小区管理")
    @PreAuthorize("@ss.hasPermi('system:community:remove')")
    @Log(title = "小区管理" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return toAjax(iZsyyCommunityService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
